Skip to content

Implementing string and byte[] async response handlers. Porting over … #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 15, 2017

Conversation

shorea
Copy link
Contributor

@shorea shorea commented Sep 14, 2017

…temp fixes so PutObject will work

* @param <ResponseT> Pojo response type.
* @return AsyncResponseHandler instance.
*/
static <ResponseT> AsyncResponseHandler<ResponseT, String> dumpToString() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "dump"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString was taken. I can rename it to toUtf8String and have a toString that takes a Charset though per your other suggestion.


@Override
public void onNext(ByteBuffer byteBuffer) {
invokeSafely(() -> baos.write(BinaryUtils.copyBytesFrom(byteBuffer)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be going crazy because I can't find that this method actually exists. http://docs.oracle.com/javase/8/docs/api/?java/io/ByteArrayOutputStream.html What am I missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to copyBytesFrom, or can we just use array since the output stream copies it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can assume it's backed by an array or that array constitutes the entire contents of the byte buffer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess we would need to check if it hasArray and preserve the indices if we were to do it.


@Override
public String complete() {
return new String(byteArrayResponseHandler.complete(), StandardCharsets.UTF_8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is their data, we should probably make them define the encoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I'll add that.


if (msg instanceof StreamedHttpResponse) {
requestContext.handler().onStream(new PublisherAdapter((StreamedHttpResponse) msg, channelContext, requestContext));
} else if (msg instanceof FullHttpResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix all of the remaining empty-response integration test failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, should fix them.

}

@SafeVarargs
private static void removePerRequestHandlers(ChannelHandlerContext ctx, Class<? extends ChannelHandler>... handlerClasses) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be varargs anymore? I only see one use. It could even be inlined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah I can inline it. Copied it from my other branch which removes some timeout handlers but didn't port that over.

@@ -134,20 +196,18 @@ public void onNext(HttpContent httpContent) {

@Override
public void onError(Throwable t) {
subscriber.onError(t);
runAndLogError("Subsriber#onError threw an exception", () -> subscriber.onError(t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsriber -> Subscriber (here and elsewhere). Will the subscriber be the customer's? Could it be beneficial to log which one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in this context it will be the customers subscriber. Were you thinking like a class name or something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a class name or just calling toString on it. We could implement useful toStrings for our internal implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for toString, I'll do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

@shorea shorea force-pushed the shorea-async-response-handler-string branch 3 times, most recently from b4d4bb5 to 1376635 Compare September 15, 2017 18:26
* Creates an {@link AsyncResponseHandler} that writes all content to UTF8 encoded string.
*
* @param <ResponseT> Pojo response type.
* @return AsyncResponseHandler instance.
Copy link
Contributor

@millems millems Sep 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@param charset + other javadoc changes

Copy link
Contributor

@millems millems left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than the minor other comments.

* @param <ResponseT> Pojo response type.
*/
@SdkInternalApi
class StringAsyncResponseHandler<ResponseT> implements AsyncResponseHandler<ResponseT, String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString()?

* @param <ResponseT> Pojo response type.
*/
@SdkInternalApi
class ByteArrayAsyncResponseHandler<ResponseT> implements AsyncResponseHandler<ResponseT, byte[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toString()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually the subscriber we call toString on. Since the byte subscriber didn't have any identifying state I just left it as the default implementation. I can change it to whatever though, just let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, it's aight.

@shorea shorea force-pushed the shorea-async-response-handler-string branch from 1376635 to bba549c Compare September 15, 2017 19:23
@shorea shorea force-pushed the shorea-async-response-handler-string branch from bba549c to 5ff3309 Compare September 15, 2017 19:26
@shorea shorea merged commit 0f6a19d into master Sep 15, 2017
@zoewangg zoewangg deleted the shorea-async-response-handler-string branch December 6, 2017 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants